let id = 0;
class Dep {
  constructor() {
    this.id = id; //属性的dep要收集watcher
    this.subs = []; //存放当前属性对应的watcher
  }
  depend() {
    // 不希望重复的watcher
    // this.subs.push(Dep.target);
    Dep.target.addDep(this); //让watcher记住dep
  }
  addSub(watcher) {
    // 实现双向的记录
    this.subs.push(watcher);
  }
  notify() {
    // 更新
    this.subs.forEach((watcher) => watcher.update());
  }
}
Dep.target = null;
let stack = [];
export function pushTarget(watcher) {
  stack.push(watcher);
  Dep.target = watcher;
}

export function popTarget() {
  stack.pop();
  Dep.target = stack[stack.length - 1];
}
export default Dep;
